package org.example.datastructure.ch2;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;

public class LongLongInt {
    boolean sign;
    List<Integer> num = new ArrayList();

    public LongLongInt(){
        this.sign = true;
        this.num = new ArrayList();

    }
    public LongLongInt(Integer[] nums){
        this.sign = true;
        this.num = Arrays.asList(nums);

        Collections.reverse(this.num);

    }
    public LongLongInt(boolean sign,Integer[] nums){
        this.sign = sign;
        this.num = Arrays.asList(nums);
        Collections.reverse(this.num);
    }

    public LongLongInt add(LongLongInt other){
         LongLongInt res = new LongLongInt();
         int len1 = this.num.size();
         int len2 = other.num.size();
         int car = 0;
         int n = 0;
         int len = Math.max(len1,len2);
         for(int i=0;i<len;i++){
             n = 0;

             if(i<len1){
                 n += this.num.get(i);

             }
             if(i<len2){
                 n += other.num.get(i);
             }
             n += car;
             car = n/10;
             n = n%10;

             res.num.add(n);
         }
         if(car!=0){
             res.num.add(car);
         }
         return res;
    }

    public void print(){
        Collections.reverse(this.num);
        this.num.stream()
                .forEach((i)->{
                    System.out.print(i+" ");
                });
        Collections.reverse(this.num);
        System.out.println();
    }
}
